<template>
	<!-- 修改昵称 -->
	<view class="modify-psw-box">
		<nav-bar :title="i18n.set.modifyNick" @_back="_back" />
		<view class="container-box">
			<custom-list :title="i18n.set.modifyNick">
				<input v-model="info.nickname" type="text" :placeholder="i18n.set.enterModifyNick">
			</custom-list>
			<custom-submit :loading="loading" style="margin-top: 100rpx;" :title="i18n.common.save" @click="submit" />
		</view>
	</view>
</template>

<script>
	import {
		Toast
	} from '@/utils/util.js'
	import mixin from '@/utils/minix.js'
	import CustomList from '@/components/CustomList/index.vue'
	import CustomSubmit from '@/components/CustomSubmit/index.vue'
	import { userNickname } from '@/api/index.js'
	import { mapGetters } from 'vuex'
	export default {
		mixins: [mixin],
		components: {
			CustomList,
			CustomSubmit
		},
		computed: {
			...mapGetters(['token']),
			i18n() {
				return this.$t('message');
			},
		},
		data() {
			return {
				info: {},
				loading: false
			}
		},
		methods: {
			async submit() {
				if (!this.info.nickname) return Toast('请输入您的昵称');
				this.info.token = this.token;
				this.loading = true;
				let { error,res } = await userNickname(this.info);
				if (error) return this.loading = false;;
				await Toast(this.i18n.login.modifySuccess);
				this.loading = false;
				this.$store.commit('user/SET_NICKNAME', this.info.nickname);
				this._back();
			}
		}
	}
</script>

<style>
</style>
